package com.zxw.common.core.base.res;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zxw.common.core.base.enums.ResponseEnum;
import lombok.Data;

import java.util.List;

/**
 * @author Xuewei.Zhang
 * @date 2022/3/17
 */
@Data
public class BasePageRes<T> {

    private Integer code;

    private List<T> data;

    private Long total;

    private String msg;

    public static <T> BasePageRes<T> success(IPage<T> page) {
        BasePageRes<T> basePageRes = new BasePageRes<>();
        basePageRes.setCode(ResponseEnum.OK.getCode());
        basePageRes.setData(page.getRecords());
        basePageRes.setTotal(page.getTotal());
        basePageRes.setMsg(ResponseEnum.OK.getMsg());
        return basePageRes;
    }

}
